/*
 * VHTabPanelLeague.java
 * Created on 27 juin 2009
 *
 * VirtualHockey Internet Platform
 * http://code.google.com/p/virtualhockey/
 *
 * Copyright (c) 2005-2009, Jens and Jan Janke (VirtualHockey Project)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see http://www.gnu.org/licenses/.
 */

package com.hockeo.vhweb.client.ui.panels;

import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.TabPanelEvent;
import com.extjs.gxt.ui.client.widget.TabItem;
import com.extjs.gxt.ui.client.widget.TabPanel;
import com.hockeo.vhweb.client.mvc.VHController;
import com.hockeo.vhweb.client.ui.base.VHTabItem;
import com.hockeo.vhweb.client.ui.tabs.VHLeagueClubListTab;
import com.hockeo.vhweb.client.ui.tabs.VHLeagueEternalStandingsTab;
import com.hockeo.vhweb.client.ui.tabs.VHLeagueHistoryTab;
import com.hockeo.vhweb.client.ui.tabs.VHLeagueStandingsTab;
import com.hockeo.vhweb.client.ui.tabs.VHWinnerListTab;
import com.hockeo.vhweb.client.utils.VHJsData;

/**
 * Tab panel providing access to league specific information.
 *
 * @version $Id$
 * @author janjanke
 */
public class VHTabPanelLeague extends TabPanel
{
  private VHController d_controller;
  private VHJsData     d_league;

  /**
   * Builds a new VHTabPanelLeague.
   *
   * @param league the model identifying the league to be represented
   */
  public VHTabPanelLeague( VHController controller, VHJsData league )
  {
    d_controller = controller;
    d_league = league;

    setBorders( false );
    setAutoWidth( true );
    setDeferHeight( true );
    setTabScroll( true );

    // Tabs
    //
    TabItem tabItem;

    tabItem = new VHLeagueStandingsTab( controller, league );
    add( tabItem );

    tabItem = new VHLeagueClubListTab( controller, league );
    add( tabItem );

    tabItem = new VHWinnerListTab( controller, league.getId() );
    add( tabItem );

    tabItem = new VHLeagueEternalStandingsTab( controller, league );
    add( tabItem );

    tabItem = new VHLeagueHistoryTab( controller, league );
    add( tabItem );

    // Add event listener to make sure the tabs have their content built when they are
    // shown for the first time.
    //
    addListener( Events.Select, new Listener<TabPanelEvent>() {
      public void handleEvent( TabPanelEvent evt )
      {
        ( (VHTabItem) evt.getItem() ).buildContent();
        ( (VHTabItem) evt.getItem() ).layout();
      }
    } );
  }
}
